package uk.co.accolade.clash.multicast;

public class ByteUtil {

    public String stringFromBuffer( byte[] buffer ) {
        return new String(buffer, 0, indexOfLastCharacter( buffer ) );
    }

    private int indexOfLastCharacter( byte[] buffer ) {
        byte empty = 0;
        for( int i = buffer.length; i != 0; i-- ) {
            if( buffer[i-1] != empty ) {
                return i;
            }
        }
        return 0;
    }
}
